// JavaScript Document

var _oldShow = $.fn.show;

$.fn.show = function(speed, oldCallback) {
 return $(this).each(function() {
	var obj = $(this),
			newCallback = function() {
				if ($.isFunction(oldCallback)) {
					oldCallback.apply(obj);
				}
				obj.trigger('afterShow');
	 		};

	obj.trigger('beforeShow');

	_oldShow.apply(obj, [speed, newCallback]);
 });
}


function Login(form){
	$('#custom-error').hide();
	$.ajax({
		url: 'ajax.aspx?type=login&' + $('#' + form).serialize() + '&rnd=' + Math.random(),
		success: function(data) {
			if (data.indexOf('redirect') != -1){
				window.location.replace(data.substring(9));
			}
			else {
				$('#login').effect('shake', {times: 3}, 100, function(){
					var errorMsg = '';
																															
					if (data == 'invalidUsername'){
						errorMsg = invalidUsername;
						$('#username').select();
					}
					else if (data == 'invalidPassword') {
						errorMsg = invalidPassword;
						$('#password').select();
					}
					else if (data == 'invalidAll'){
						errorMsg = invalidAll;
						$('#username').select();
					}
					$('#loginResult').html(errorMsg);
					$('#custom-error').show();
				});			
			}
		}
	});
}